package com.blb.zycommunity.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.blb.zycommunity.entity.ResponseResult;
import com.blb.zycommunity.entity.ZyOwner;
import com.blb.zycommunity.entity.ZyOwnerRoom;
import com.blb.zycommunity.entity.ZyOwnerRoomRecord;
import com.blb.zycommunity.service.IZyOwnerRoomRecordService;
import com.blb.zycommunity.service.IZyOwnerRoomService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 房屋绑定表  前端控制器
 * </p>
 *
 * @author chenheng
 * @since 2023-11-20
 */
@RestController
public class ZyOwnerRoomController {

    @Autowired
    private IZyOwnerRoomService ownerRoomService;

    @Autowired
    private IZyOwnerRoomRecordService ownerRoomRecordService;

    @DeleteMapping("/owner-room")
    public ResponseResult removeZyOwnerRoom(@RequestParam String ownerId,@RequestParam String roomId){
        ownerRoomService.removeZyOwnerRoom(ownerId,roomId);
        return ResponseResult.ok("ok");
    }

    @GetMapping("/owner-review-pages")
    public ResponseResult<IPage<ZyOwnerRoom>> findOwnerReviewPage(@RequestParam(required = false,defaultValue = "1") Long current,
                                                              @RequestParam(required = false,defaultValue = "5") Long size,
                                                              @RequestParam(required = false) String communityId,
                                                              @RequestParam(required = false) String roomStatus){
        IPage<ZyOwnerRoom> ownerReviewPage = ownerRoomService.findOwnerReviewPage(current, size,communityId, roomStatus);
        return ResponseResult.ok(ownerReviewPage);
    }
    @PutMapping("/pass")
    public ResponseResult pass(@RequestParam String ownerRoomId){
        ownerRoomService.updatePass(ownerRoomId);
        return ResponseResult.ok("ok");
    }

    @PutMapping("/not-pass")
    public ResponseResult notPass(@RequestParam String ownerRoomId){
        ownerRoomService.updateNotPass(ownerRoomId);
        return ResponseResult.ok("ok");
    }

    @GetMapping("/uni-app-getAll")
    public ResponseResult<List<ZyOwnerRoom>> findAll(){
        List<ZyOwnerRoom> list = ownerRoomService.findAll();
        return ResponseResult.ok(list);
    }

    @PostMapping("/uni-app-add-ownerRoom")
    public ResponseResult addOwnerRoom(@RequestBody ZyOwnerRoom zyOwnerRoom){
        zyOwnerRoom.setRoomStatus("0");
        LocalDateTime time = LocalDateTime.now();
        zyOwnerRoom.setCreateTime(time);
        boolean save = ownerRoomService.save(zyOwnerRoom);
        return ResponseResult.ok(save);
    }
}

